package com.example.project.common;

import com.google.gson.Gson;


/**
 * 根据 JSON 字符串 转换对象实例 工具类
 **/
public class GsonUtils {
    private static volatile Gson gson;
    private GsonUtils() {}
    private static Gson getGson() {
        if (null == gson) {
            synchronized (GsonUtils.class) {
                if (null == gson) {
                    gson = new Gson();
                }
            }
        }
        return gson;
    }

    public static <R> R getObjFromJson(String json, Class<R> cls) {
        return getGson().fromJson(json, cls);
    }
}
